package vn.aptech.leaveManagementSystem.business;

import java.sql.Connection;
import java.util.HashMap;
import java.util.Map;

import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.view.JasperViewer;
import vn.aptech.leaveManagementSystem.dao.DBManager;

public class ViewReport {
	public void viewReportTotalDaysLeaveInDepartment(int idDep,java.util.Date fromDate,java.util.Date toDate)
	{
		try {  
            JasperDesign jasperDesign = JRXmlLoader.load("myReports/reportTotalDaysLeaveDepartment.jrxml");  
            JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);  
            DBManager db=new DBManager();
            Connection jdbcConnection =  db.getConn();
            Map m=new HashMap<String,Object>();
            m.put("idDep",idDep );
            m.put("FromDate", fromDate);
            m.put("ToDate", toDate);
            JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, m, jdbcConnection);  
     
            JasperViewer.viewReport(jasperPrint, false);  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
	}
	
	public void viewReportTotalDaysLeaveInCompany(java.util.Date fromDate,java.util.Date toDate)
	{
		try {  
            JasperDesign jasperDesign = JRXmlLoader.load("myReports/reportTotalDaysLeaveCompany.jrxml");  
            JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);  
            DBManager db=new DBManager();
            Connection jdbcConnection =  db.getConn();
            Map m=new HashMap<String,Object>();
            m.put("FromDate", fromDate);
            m.put("ToDate", toDate);
            JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, m, jdbcConnection);  
            JasperViewer.viewReport(jasperPrint, false);  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
	}
	
	public void viewStatisticalReportAboutEmployeeLeaveHistory(int idEmp,java.util.Date fromDate,java.util.Date toDate)
	{
		try {  
            JasperDesign jasperDesign = JRXmlLoader.load("myReports/reportListApplicationsOfEmployee.jrxml");
            JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);  
            DBManager db=new DBManager();
            Connection jdbcConnection =  db.getConn();
            Map m=new HashMap<String,Object>();
            m.put("EmpID", idEmp);
            m.put("FromDate", fromDate);
            m.put("ToDate", toDate);
            JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, m, jdbcConnection);  
            JasperViewer.viewReport(jasperPrint, false);  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
	}
	
	
	
}
